<template>
  <div class="topClassOutStore">
    <div class="baseDiv" v-if="this.$props.roleType===2">
      <el-form :model="addForm"  :rules="rules" ref="addForm"  class="addForm">
        <div style="border-bottom: 1px solid #e5e5e5;height: 30px;margin-top: 10px;margin-bottom: 10px">
          <span style="margin-left: 20px;">第一步: 选择出库货物</span>
        </div>
        <div style="">
          <el-form-item label="出库仓库"  prop="storageName">
            <el-select class="selectclass" :disabled="this.$props.isAdditionalInformation" v-model="addForm.storageName"  @change="getStorageOtherInfo"  filterable placeholder="请选择仓库">
              <el-option
                v-for="item in this.storageList"
                :key="item.id"
                :label="item.storageName"
                :value="item.storageName">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item class="el-form-item-right"  label="存货人" prop="ownerName">
            <el-select class="selectclass" v-model="addForm.ownerName" :disabled="this.$props.isAdditionalInformation" @change="changeInputOwner"  clearable filterable placeholder="请选择存货人">
              <el-option
                v-for="item in this.ownerList"
                :key="item.id"
                :label="item.companyName"
                :value="item.companyName">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="柜号"  prop="">
            <el-input v-model="addForm.cntrNo" v-bind:disabled="this.$props.isAdditionalInformation" @blur="validatecntrNo" maxlength="20" onkeyup="value=value.replace(/[\u4E00-\u9FA5]/g,'')" style="width: 420px" placeholder="选填项，支持填写多个柜号，以逗号分隔" clearable></el-input>
          </el-form-item>
          <el-form-item class="el-form-item-right" label="" prop="">
          </el-form-item>
          <el-form-item style="margin-top: 10px">
            <el-button v-if="this.$props.isAdditionalInformation" class="singleBtnClass el-buttonBackColor" v-bind:disabled="true" @click="serachFn()" type="primary">搜索</el-button>
            <el-button v-else class="singleBtnClass"  @click="serachFn()" type="primary">搜索</el-button>
          </el-form-item>
        </div>
      </el-form>
    </div>

    <div class="baseDivOwner" v-if="this.$props.roleType===3">
      <el-form :model="addForm" :rules="rules"  ref="addForm"  class="addForm">
        <div style="border-bottom: 1px solid #e5e5e5;height: 30px;margin-top: 10px;margin-bottom: 10px">
          <span style="margin-left: 20px;">第一步: 选择出库货物</span>
        </div>
        <div style="">
          <el-form-item label="出库仓库"  prop="storageName">
            <el-select class="selectclass" :disabled="this.$props.isAdditionalInformation" v-model="addForm.storageName"  @change="getStorageOtherInfo"   filterable placeholder="请选择仓库">
              <el-option
                v-for="item in this.storageList"
                :key="item.id"
                :label="item.storageName"
                :value="item.storageName">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item class="el-form-item-right" label="柜号" prop="">
            <el-input v-model="addForm.cntrNo" v-bind:disabled="this.$props.isAdditionalInformation" @blur="validatecntrNo" style="width: 420px" maxlength="20" onkeyup="value=value.replace(/[\u4E00-\u9FA5]/g,'')" placeholder="选填项，支持填写多个柜号，以逗号分隔" clearable></el-input>
          </el-form-item>
          <el-form-item style="margin-top: 10px">
            <el-button class="singleBtnClass" @click="serachFn()" type="primary">搜索</el-button>
          </el-form-item>
        </div>
      </el-form>
    </div>
    <div label="" v-if="isShowInfo" style="width: 958px;" prop="">
      <el-table border :data="this.goodList" @row-click="choseOneGoods" @selection-change="handleSelectionChange"  ref="detailTable" style="margin-top: 20px;margin-bottom:10px;width: 100%" class="in-store-table" >
        <el-table-column
          :selectable="selectableFn"
          type="selection"
          width="38">
        </el-table-column>
        <el-table-column prop="wrBusinessNo" label="仓单业务号"  :show-overflow-tooltip="true" align="center" v-bind:width="140" style="width:6vw;" >
          <div slot-scope="scope" class="hiddenOverText">
            {{scope.row.wrBusinessNo}}
          </div>
        </el-table-column>
        <el-table-column prop="goodsName" label="货物名称" :show-overflow-tooltip="true" align="center" v-bind:width="110" style="width:6vw;" >
          <div slot-scope="scope" class="hiddenOverText">
            {{scope.row.goodsName}}
          </div>
        </el-table-column>
        <el-table-column prop="cntrNo" label="柜号" :show-overflow-tooltip="true"  align="center" v-bind:width="140" style="width:6vw;" >
          <div slot-scope="scope" class="hiddenOverText">
            {{scope.row.cntrNo}}
          </div>
        </el-table-column>
        <el-table-column prop="vendor" label="生产厂家"  :show-overflow-tooltip="true" align="center" v-bind:width="110" style="width:6vw;" >
          <div slot-scope="scope" class="hiddenOverText">
            {{scope.row.vendor}}
          </div>
        </el-table-column>
        <el-table-column prop="countryOrigin" label="原产地"align="center" :show-overflow-tooltip="true" v-bind:width="110" style="width:6vw;" >
          <div slot-scope="scope" class="hiddenOverText">
            {{scope.row.countryOrigin}}
          </div>
        </el-table-column>
        <el-table-column prop="packageName" label="包装"align="center" v-bind:width="110" style="width:6vw;" >
          <div slot-scope="scope">
            {{scope.row.packageName}}
          </div>
        </el-table-column>
        <el-table-column prop="productDate" label="生产日期" align="center" v-bind:width="110" style="width:6vw;" >
          <div slot-scope="scope">
            {{scope.row.productDate}}
          </div>
        </el-table-column>
        <el-table-column prop="unitName" label="单位"align="center" v-bind:width="110" style="width:6vw;" >
          <div slot-scope="scope">
            {{scope.row.unitName}}
          </div>
        </el-table-column>
        <el-table-column prop="wsStockNum" label="库存数量" align="center" v-bind:width="110" style="width:12vw;" >
          <div slot-scope="scope">
            {{scope.row.wsStockNum}}
          </div>
        </el-table-column>
        <el-table-column prop="avaStockNum" label="可用库存数量" align="center" v-bind:width="140" style="width:12vw;" >
          <div slot-scope="scope">
            {{scope.row.avaStockNum}}
          </div>
        </el-table-column>
        <el-table-column prop="planCount" label="计划出库数量" align="center" v-bind:width="140" style="width:12vw;" >
          <div slot-scope="scope">
            <el-input size="mini" v-model="scope.row.planCount" maxlength="8" clearable @keyup.native="verifyInteger(scope.row, '','planCount')" ></el-input>
          </div>
        </el-table-column>
        <el-table-column v-if="this.$props.roleType===2"  prop="actCount" label="实际出库数量" align="center" v-bind:width="140" style="width:12vw;" >
          <div slot-scope="scope">
            <el-input size="mini" v-model="scope.row.actCount" maxlength="8" clearable @input="changeActCountValue(scope.row)" @keyup.native="verifyInteger(scope.row, scope.$index, 'actCount')" ></el-input>
          </div>
        </el-table-column>
        <el-table-column prop="outWeight" v-if="this.$props.roleType===2"  label="出库重量(kg)" align="center" v-bind:width="140" style="width:12vw;" >
          <div slot-scope="scope">
            {{scope.row.outWeight}}
          </div>
        </el-table-column>
        <el-table-column v-if="this.$props.roleType===2"  prop="scanWeight" label="抄码重量(kg)" align="center" v-bind:width="140" style="width:12vw;" >
          <div slot-scope="scope">
            <el-input size="mini" v-model="scope.row.scanWeight" v-bind:disabled="responseData.scanFiles.length===0" maxlength="10" clearable @keyup.native="verifyDecimal(scope.row, 'scanWeight')" ></el-input>
          </div>
        </el-table-column>
        <el-table-column v-if="this.$props.roleType===3"  prop="outWeight" label="库存重量(kg)" align="center" v-bind:width="140" style="width:12vw;" >
          <div slot-scope="scope">
            {{scope.row.wsStockWeight}}
          </div>
        </el-table-column>
      </el-table>

      <div class="baseDiv" style="height: 240px;margin-bottom: 10px;margin-top: 20px">
        <el-form :model="addFormSecond" :rules="rulesSecond" ref="addFormSecond"  class="addForm">
          <div style="border-bottom: 1px solid #e5e5e5;height: 30px;margin-top: 10px;">
            <span style="margin-left: 20px;">第二步: 填写出库信息</span>
          </div>
          <div style="margin-top: 10px">
            <el-form-item label="出库日期"  prop="outStoreDate">
              <el-date-picker type="date" v-model="addFormSecond.outStoreDate" clearable format="yyyy-MM-dd" value-format="yyyy-MM-dd"  placeholder="请输入出库日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item class="el-form-item-right" label="提货人姓名" prop="consignee">
              <el-input v-model="addFormSecond.consignee" style="width: 420px" maxlength="50" placeholder="请输入提货人姓名" clearable></el-input>
            </el-form-item>
            <el-form-item label="提货人电话"  prop="mobile">
              <el-input v-model="addFormSecond.mobile" style="width: 420px" maxlength="15" placeholder="请输入提货人电话" clearable></el-input>
            </el-form-item>
          </div>
        </el-form>
        <file-upload v-if="this.$props.roleType===2" :roleType="this.$props.roleType" :fromType="1" :headTitle="'提交出库录单资料'" :fileUrlsArray="this.responseData" :headSonTitle="'支持pdf,jpg,png,gif,bmp,xls,xlsx,csv,doc,docx (最多选择5张)'" @getFileUrls="getFileUrls" ></file-upload>
        <input-com v-if="this.$props.roleType===2" :headTitle="'货主备注(选填)'" :inputValue="this.responseData.remark"  @getInputVal="getInputOwnerVal" :headSonTitle="'填写备注'"></input-com>
        <input-com v-if="this.$props.roleType===2":headTitle="'客服备注(选填)'" :inputValue="this.responseData.customerRemark"  @getInputVal="getInputCustomerVal" :headSonTitle="'填写备注'"></input-com>
        <input-com v-if="this.$props.roleType===3":headTitle="'备注(选填)'" :inputValue="this.responseData.remark"  @getInputVal="getInputOwnerVal" :headSonTitle="'填写备注'"></input-com>
        <div class="btnFrameClass" v-if="hasPermission('wms:outstore:save')&&hasPermission('wms:outstore:submmit')">
          <el-button class="singleBtnClass" v-permission="['wms:outstore:save']" @click="saveOutStore(1)" type="primary" plain>保存</el-button>
          <el-button class="singleBtnClass" v-permission="['wms:outstore:submmit']" @click="submitForm('addForm','addFormSecond',2)" type="primary">提交</el-button>
        </div>
        <div v-if="hasPermission('wms:outstore:save')&&!hasPermission('wms:outstore:submmit')" class="btnFrameClassOwner">
          <el-button class="singleBtnClass" v-permission="['wms:outstore:save']"  @click="saveOutStore(1)" type="primary" plain>保存</el-button>
        </div>
        <div v-if="hasPermission('wms:outstore:submmit')&&!hasPermission('wms:outstore:save')" class="btnFrameClassOwner">
          <el-button class="singleBtnClass" v-permission="['wms:outstore:submmit']" @click="submitForm('addForm','addFormSecond',2)" type="primary">提交</el-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import maValidate from 'utils/common-method/validate/index';
  import inputCom from 'components/input/baseTitleInput.vue';
  import fileUpload from 'components/fileUpload/file.vue';
  import {validateTips} from 'utils/tips';
  import PcDialog from 'components/dialog';
  import searchSelect from 'components/search-select/searchSelect';
  export default {
    components: {
      inputCom,
      fileUpload,
      PcDialog,
      searchSelect
    },
    props: {
      roleType: {
        type: Number
      },
      detailId: {
        type: String
      },
      isAdditionalInformation: {
        type: Boolean
      }
    },
    data() {
      return {
        isShowInfo: false,
        outstoreFiles: [], // 出库单数组
        scanFiles: [], // 抄码单数组
        storageList: [], // 下拉选择仓库
        ownerList: [], // 下拉选择货主
        cntrNoArr: [],
        goodListDetail: [], // 详情获取的货物数据
        goodListSelect: [], // 选择的货物列表
        goodList: [{
          avaStockNum: '', // 可用库存数量
          cntrNo: '', // 柜号
          planCount: '',
          actCount: '',
          scanWeight: '',
          countryOrigin: '', // 原产地
          goodsId: '', // 货物ID编号
          goodsName: '', // 货物名称
          packageId: '', // 包装
          packageName: '', // 包装
          productDate: '', // 生产日期
          refAvgWeight: '', // 入库平均重量
          unit: '', // 单位
          unitName: '', // 单位
          vendor: '', // 生产厂家
          wrBusinessNo: '', // 仓单业务号
          wsStockNum: '', // 仓单库存数量
          wsStockWeight: '',  // 库存重量
          outWeight: '' // 出库重量
        }],
        responseData: {
          operateType: '',
          businessType: '',
          consignee: '',
          cntrNo: '',
          customerRemark: '',
          mobile: '',
          id: null,
          outStoreDate: '',
          resource: '',
          outStoreDetails: null,
          outStoreFiles: [], // 出库单数组
          ownerId: null,
          storageName: '',
          ownerName: '',
          remark: '',
          scanFiles: [], // 抄码单数组
          storageId: null
        },
        addForm: {
          storageName: '',
          storageId: '',
          ownerName: '',
          ownerId: '',
          cntrNo: ''
        },
        addFormSecond: {
          consignee: '',
          mobile: '',
          outStoreDate: ''
        },
        rules: {
          storageName: [
            {required: true, message: validateTips.FILL_BASE_INFO, trigger: 'blur'}
          ],
          ownerName: [
            {required: true, message: validateTips.FILL_BASE_INFO, trigger: 'blur'}
          ]
        },
        rulesSecond: {
          outStoreDate: [
            {required: true, message: validateTips.FILL_BASE_INFO, trigger: 'blur'},
            {min: 0, max: 150, message: validateTips.WORD_LESS_150, trigger: 'blur'}
          ],
          consignee: [
            {required: true, message: validateTips.FILL_BASE_INFO, trigger: 'blur'},
            {min: 0, max: 150, message: validateTips.WORD_LESS_150, trigger: 'blur'}
          ],
          mobile: [
            {required: true, message: validateTips.FILL_BASE_INFO, trigger: 'blur'},
            {validator: maValidate.checkMobileNo, trigger: 'blur'}
          ]
        }
      };
    },
    created() {
      if (this.$props.isAdditionalInformation) {
        this.getDetailInfo(); // 补充资料获取详情
      } else {
        this.getStorageInfo(); // 获取仓库数据
      }
    },
    computed: {
    },
    methods: {
      validatecntrNo() {
        let reg = /^[A-Za-z0-9]{1,20}$/;
        if (!reg.test(this.addForm.cntrNo)) {
          this.addForm.cntrNo = null;
        }
      },
      serachFn() {
        // if (this.$props.roleType === 2) {
        //   if (!this.addForm.storageId || !this.addForm.ownerId || this.addForm.storageId === null || this.addForm.ownerId === null) {
        //     this.$pcMessage.error('请选择出库仓库和存货人');
        //     return false;
        //   }
        // }
        // if (this.$props.roleType === 3) {
        //   if (!this.addForm.storageId || this.addForm.storageId === null) {
        //     this.$pcMessage.error('请选择出库仓库');
        //     return false;
        //   }
        // }
        this.$refs['addForm'].validate((valid) => {
          if (!valid) {
            return false;
          } else {
            this.addForm.cntrNo = this.addForm.cntrNo.replace('，', ',', this.addForm.cntrNo);
            this.ajax({
              type: 'POST',
              url: '/maliwms/outStore/listOutStoreGoods',
              data: {storageId: this.addForm.storageId, ownerId: this.addForm.ownerId, cntrNo: this.addForm.cntrNo},
              loading: true,
              success: (res) => {
                setTimeout(() => {
                  this.$pcNProgress.done();
                }, 300);
                if (res.code === 200) {
                  this.goodList = res.result;
                  if (this.goodList.length > 0) {
                    this.isShowInfo = true;
                  } else {
                    this.isShowInfo = false;
                  }
                  if (this.goodList.length === 0) {
                    this.errorTip('货物数据为空');
                  }
                } else {
                  this.errorTip(res.message);
                }
              }
            });
          }
        });
      },
      selectableFn(row, index) {
        // console.info(row);
        return row.id !== '1';
      },
      choseOneGoods(row) {
        this.$refs.detailTable.toggleRowSelection(row, true);
      },
      handleSelectionChange(goodlist) {
        this.goodListSelect = [];
        this.goodListSelect = goodlist;
      },
      // 获取货主企业信息
      getOwnerInfo() {
        this.ajax({
          type: 'POST',
          url: '/maliwms/outStore/listOwners',
          data: {storageId: this.addForm.storageId},
          loading: true,
          success: (res) => {
            setTimeout(() => {
              this.$pcNProgress.done();
            }, 300);
            this.ownerList = res.result;
          }
        });
      },
      getStorageInfo() {
        // let valueStr = JSON.stringify(['wms_unit', 'wms_package']);
        this.ajax({
          type: 'POST',
          url: '/maliwms/storage/selectStorage',
          data: {storageName: ''},
          loading: true,
          success: (res) => {
            setTimeout(() => {
              this.$pcNProgress.done();
            }, 300);
            this.storageList = res.result;
          }
        });
      },
      getDetailInfo() {
        this.isShowInfo = true;
        this.ajax({
          type: 'GET',
          url: '/maliwms/outStore/outStoreDetail/' + this.$props.detailId,
          loading: true,
          success: (res) => {
            setTimeout(() => {
              this.$pcNProgress.done();
            }, 300);
            this.addForm.storageName = res.result.storageName;
            this.addForm.storageId = res.result.storageId;
            this.addForm.ownerName = res.result.ownerName;
            this.addForm.ownerId = res.result.ownerId;
            this.addFormSecond.consignee = res.result.consignee;
            this.addFormSecond.mobile = res.result.mobile;
            this.addFormSecond.outStoreDate = res.result.outStoreDate;
            this.responseData = res.result;
            this.goodList = res.result.outStoreDetails;
            let _this = this;
            _this.$nextTick(function() {
              for (let i = 0; i < this.goodList.length; i++) {
                // this.goodList[i].outWeight = this.goodList[i].actCount * this.goodList[i].refAvgWeight;
                this.$refs.detailTable.toggleRowSelection(this.goodList[i], true);
              }
            });
          }
        });
      },
      // 校验整数
      verifyInteger(val, index, prop) {
        maValidate.verifyInteger(val, prop);
        if (prop === 'actCount') {
          val['outWeight'] = Number(val[prop] * val['refAvgWeight']).toFixed(2);
        }
      },
      changeActCountValue(val) {
        if (val['actCount'] === '') {
          val['outWeight'] = '';
        }
      },
      // 校验小数
      verifyDecimal(val, prop) {
        maValidate.verifyDecimal(val, prop);
      },
      // 下拉仓库选择
      getStorageOtherInfo: function(value) {
        for (let j = 0; j < this.storageList.length; j++) {
          if (this.storageList[j].storageName === value) {
            this.addForm.storageId = this.storageList[j].id;
            if (this.$props.roleType === 2) {
              this.getOwnerInfo();
            }
          }
        }
        this.addForm.ownerId = '';
        this.addForm.ownerName = '';
        this.isShowInfo = false;
      },
      // 下拉货主选择
      changeInputOwner(val) {
        this.addForm.ownerName = val;
        this.ownerList.forEach((item, index) => {
          if (item.companyName === val) {
            this.addForm.ownerId = item.id;
          }
        });
        if (this.$props.roleType === 2) {
          if (val === '') {
            this.addForm.ownerId = '';
            this.addForm.ownerName = '';
            this.isShowInfo = false;
          }
        }
      },
      getFileUrls(titleImg, fileNameArr, fileUrlArr) {
        if (titleImg === '出库单') {
          this.responseData.outStoreFiles = [];
          for (let i = 0; i < fileUrlArr.length; i++) {
            let singleImg = {name: '', url: ''};
            singleImg.name = fileNameArr[i];
            singleImg.url = fileUrlArr[i];
            this.responseData.outStoreFiles.push(singleImg);
          }
        }
        if (titleImg === '抄码单') {
          this.responseData.scanFiles = [];
          for (let i = 0; i < fileUrlArr.length; i++) {
            let singleImg = {name: '', url: ''};
            singleImg.name = fileNameArr[i];
            singleImg.url = fileUrlArr[i];
            this.responseData.scanFiles.push(singleImg);
          }
          if (this.responseData.scanFiles.length === 0) {
            this.goodList.forEach((item, index) => {
              item.scanWeight = '';
            });
          }
        }
      },
      getInputOwnerVal(val) {
        this.responseData.remark = val;
      },
      getInputCustomerVal(val) {
        this.responseData.customerRemark = val;
      },
      removeOtherPara (urlArray) {  // 移除url 数组 多出来的 uid status字段
        if (urlArray.length > 0) {
          for (let i = 0; i < urlArray.length; i++) {
            if (urlArray[i].uid !== '') {
              delete urlArray[i].uid;
            }
            if (urlArray[i].status !== '') {
              delete urlArray[i].status;
            }
          }
        }
      },
  // 提交入库数据函数
      submitForm(formName, formNameSecond, operateType) {
        this.$refs[formName].validate((valid) => {
          if (!valid) {
            return false;
          } else {
            this.$refs[formNameSecond].validate((valid) => {
              if (!valid) {
                return false;
//            alert('submit!');
              } else {
                this.saveOutStore(operateType);
              }
            });
          }
        });
      },
      saveOutStore(operateType) {
        if (this.$props.isAdditionalInformation) {
          this.responseData.businessType = 2; // 补充资料
        } else {
          this.responseData.businessType = 1; // 出库录单
        }
        if (operateType === 1) {
          this.responseData.operateType = 1; // 保存
        } else {
          if (this.$props.roleType === 2) {
            this.responseData.operateType = 2; // 提交
          } else {
            this.responseData.operateType = null; // 提交
          }
        }
        this.responseData.storageName = this.addForm.storageName;
        this.responseData.storageId = this.addForm.storageId;
        this.responseData.ownerName = this.addForm.ownerName;
        this.responseData.ownerId = this.addForm.ownerId;
        this.responseData.consignee = this.addFormSecond.consignee;
        this.responseData.mobile = this.addFormSecond.mobile;
        this.responseData.outStoreDate = this.addFormSecond.outStoreDate;
        this.responseData.cntrNo = this.addForm.cntrNo;
        this.responseData.outStoreDetails = this.goodListSelect;
        this.responseData.id = this.$props.detailId;
        this.removeOtherPara(this.responseData.outStoreFiles);
        this.removeOtherPara(this.responseData.scanFiles);
        let totolPlanCount = 0;
        let totolActCount = 0;
        if (operateType === 2) {
          if (this.responseData.outStoreDetails.length === 0) {
            this.errorTip('请选择出库货物！');
            return false;
          } else {
            for (let i = 0; i < this.responseData.outStoreDetails.length; i++) {
              if (this.$props.roleType === 2) {
                totolPlanCount = parseInt(totolPlanCount) + parseInt(this.responseData.outStoreDetails[i].planCount);
                totolActCount = parseInt(totolActCount) + parseInt(this.responseData.outStoreDetails[i].actCount);
                if ((this.responseData.outStoreDetails[i].planCount === '') || (this.responseData.outStoreDetails[i].actCount === '') || ((!this.responseData.outStoreDetails[i].scanWeight || this.responseData.outStoreDetails[i].scanWeight === '') && this.responseData.scanFiles.length > 0)) {
                  this.errorTip('请完善货物信息！');
                  return false;
                }
                if (this.responseData.outStoreDetails[i].planCount > this.responseData.outStoreDetails[i].avaStockNum) {
                  this.errorTip('计划出库数量超额，请检查！');
                  return false;
                }
                if (this.responseData.outStoreDetails[i].actCount > this.responseData.outStoreDetails[i].avaStockNum) {
                  this.errorTip('实际出库数量超额，请检查！');
                  return false;
                }
              } else {
                totolPlanCount = parseInt(totolPlanCount) + parseInt(this.responseData.outStoreDetails[i].planCount);
                if (this.responseData.outStoreDetails[i].planCount === '' || !this.responseData.outStoreDetails[i].planCount) {
                  this.errorTip('请完善货物信息！');
                  return false;
                }
                if (this.responseData.outStoreDetails[i].planCount > this.responseData.outStoreDetails[i].avaStockNum) {
                  this.errorTip('计划出库数量超额，请检查！');
                  return false;
                }
              }
            }
            if (!totolPlanCount) {
              this.errorTip('请完善货物信息!');
              return false;
            }
            if (this.$props.roleType === 2) {
              if (!totolActCount) {
                this.errorTip('请完善货物信息');
                return false;
              }
            }
          }
          if (this.responseData.outStoreFiles.length === 0 && this.$props.roleType === 2) {
            this.errorTip('请上传出库单!');
            return false;
          }
        } else {
          this.$refs['addForm'].validate((valid) => {
            if (!valid) {
              return false;
            }
          });
          if (this.responseData.outStoreDetails.length === 0) {
            this.errorTip('请选择出库货物！');
            return false;
          }
          if (this.responseData.outStoreDetails.length > 0) {
            for (let i = 0; i < this.responseData.outStoreDetails.length; i++) {
              totolPlanCount = parseInt(totolPlanCount) + parseInt(this.responseData.outStoreDetails[i].planCount);
              totolActCount = parseInt(totolActCount) + parseInt(this.responseData.outStoreDetails[i].actCount);
              if (((this.responseData.outStoreDetails[i].planCount === '')) || (this.responseData.outStoreDetails[i].actCount === '') || ((!this.responseData.outStoreDetails[i].scanWeight || this.responseData.outStoreDetails[i].scanWeight === '') && this.responseData.scanFiles.length > 0)) {
                this.errorTip('请完善货物信息！');
                return false;
              }
              if (this.responseData.outStoreDetails[i].planCount > this.responseData.outStoreDetails[i].avaStockNum) {
                this.errorTip('计划出库数量超额，请检查！');
                return false;
              }
              if (this.responseData.outStoreDetails[i].actCount > this.responseData.outStoreDetails[i].avaStockNum) {
                this.errorTip('实际出库数量超额，请检查！');
                return false;
              }
            }
            if (!totolPlanCount) {
              this.errorTip('请完善货物信息！');
              return false;
            }
            if (!totolActCount) {
              this.errorTip('请完善货物信息！');
              return false;
            }
          }
        }
        this.ajax({
          type: 'POST',
          url: '/maliwms/outStore/saveOutStore',
          data: this.responseData,
          loading: true,
          success: (res) => {
            setTimeout(() => {
              this.$pcNProgress.done();
            }, 300);
            if (res.code === 200) {
              this.$emit('closeRefresh');
            } else {
              this.errorTip(res.message);
            }
          }
        });
      }
    }
  };
</script>
<style scoped>
  .topClassOutStore {
    background-color: #f5f6f7;
    width: 958px
  }
  .baseDiv {
    display: flex;
    flex-wrap: wrap;
    width: 958px;
    height: 300px;
    border: 1px solid #e5e5e5;
    background-color: white
  }

  .baseDiv .el-form-item {
    display: inline-block;
    width: 420px;
    margin-left: 20px;
    margin-right: 20px;
  }
  .baseDiv .el-form-item-right {
    float: right;
  }
  .baseDiv .el-form-item .el-input {
    width: 420px;
  }

  .baseDivOwner {
    display: flex;
    flex-wrap: wrap;
    width: 958px;
    height: 220px;
    border: 1px solid #e5e5e5;
    background-color: white
  }

  .baseDivOwner .el-form-item {
    display: inline-block;
    width: 420px;
    margin-left: 20px;
    margin-right: 20px;
  }
  .baseDivOwner .el-form-item-right {
    float: right;
  }
  .baseDivOwner .el-form-item .el-input {
    width: 420px;
  }
  .addForm{
    margin-top:10px;
    margin-bottom: 20px;
    /*width:1000px;*/
  }
  .btnFrameClass
  {
    width: 100%;
    margin-top: 40px;
    margin-bottom: 20px;
    text-align: center;
  }
  .btnFrameClassOwner
  {
    width: 100%;
    margin-top: 40px;
    margin-bottom: 20px;
    text-align: center;
  }
  .singleBtnClass
  {
    width: 140px;
    height: 40px;
  }
  .selectclass {
    width: 420px;
  }
  .maliiconfont {
    color: #808080;
  }

  .in-store-table .cell {
    text-align: center !important;
    color: #333333 !important;
  }

  .in-store-table .el-input__inner {
    text-align: center !important;
  }
  .el-buttonBackColor {
     background-color: #d1e5fd !important;
     border-color: #d1e5fd !important;
  }
  .hiddenOverText {
    max-height: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
    line-height: 23px;
  }
</style>
